package com.uzai.console.web;

import com.uzai.console.constant.CommonConstant;
import com.uzai.console.vo.login.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther: liuqi
 * @Date: 2021/8/10 14:48
 * @Description:
 */
public class BaseController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取当前请求
     * @return
     */
    public HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    /**
     * 获取当前响应
     * @return
     */
    public HttpServletResponse getResponse() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }

    /**
     * 获取登录用户
     * @return
     */
    public LoginVo getLoginInfo() {
        return (LoginVo)getRequest().getAttribute(CommonConstant.LOGIN_MERCHANT_CONSOLE);
    }
}
